package com.nondo.dean.saprfc.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.nondo.dean.saprfc.controller.CrmProductBomController;
import com.nondo.dean.saprfc.controller.CrmProductController;
import com.nondo.dean.saprfc.controller.CrmUserController;
import com.nondo.dean.saprfc.model.OrderSubjectBean;

/**
 * @author xiaofan
 * @Description: 定时同步管理
 * @throws
 * @date 2018-06-1113:46
 * @Version
 */
@Component
public class TimedTaskManage {

    private static final Logger logger = LoggerFactory.getLogger(TimedTaskManage.class);

    @Autowired
    CrmProductController crmProductController;

    @Autowired
    CrmProductBomController crmProductBomController;

    @Autowired
    CrmUserController crmUserController;

    @Autowired
    CrmOrderStautsService crmOrderStautsService;

    /**
     * 同步 产品 BOM结构  经销商 数据
     */
    //@Scheduled(cron="0 0/1 * * * ?")
    public void synUserAndProduct(){
        crmProductController.getTheProduct();
        crmProductBomController.getSapBom();
        crmUserController.getUser();
    }

    /**
     * 同步sap返回的订单状态用于更新app订单状态
     */
    @Scheduled(cron="0 0/30 * * * ?")
    public void synAppOrderStauts(){
        logger.info("开始执行更新订单状态.........");
        
        List<OrderSubjectBean> orderSubjectList = crmOrderStautsService.getWaittingToDeliverOrderList();
        for (OrderSubjectBean orderSubject : orderSubjectList) {
            crmOrderStautsService.updateAppOrderStauts(orderSubject);
        }

    }

}
